From 6e3522ab2c44c90da28d1064a2f56c3a7184f749 Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Sun, 2 Jan 2000 03:59:22 +0000 Subject: [PATCH] Added reference counting to animations. A web browser may want to share a 2000-01-01 Federico Mena Quintero * gdk-pixbuf/gdk-pixbuf.h (GdkPixbufAnimation): Added reference counting to animations. A web browser may want to share a single copy of an animated GIF if it appears multiple times in a web page, for example. * gdk-pixbuf/gdk-pixbuf-animation.c: New file. Moved the animation functions here. (gdk_pixbuf_animation_new_from_file): Prettified. Return a NULL animation if the loader does not support multiframe loading and the single-frame load returned NULL. Check that the filename is not NULL. Updated inline documentation. (gdk_pixbuf_animation_ref): New function. (gdk_pixbuf_animation_unref): New function. Removed gdk_pixbuf_animation_destroy() in favor of reference counting. * gdk-pixbuf/gdk-pixbuf-io.c (gdk_pixbuf_new_from_file): Prettified. Made ref_count assertion more paranoid. Check that the filename is not NULL. (gdk_pixbuf_get_module): Use guchar * and guint for buffer and size, respectively. (gdk_pixbuf_new_from_xpm_data): Changed the "data" argument to const char **. * gdk-pixbuf/io-gif.c (image_load_animation): Create the animation with a reference count of 1. * gdk-pixbuf/Makefile.am (libgdk_pixbuf_la_SOURCES): Added gdk-pixbuf-animation.c. * doc/tmpl/animation.sgml: Populated. It is still missing a description of the overlay modes. * doc/gdk-pixbuf-sections.txt: Added the animation section. Moved the canvas item section to the end, as it will be moved later to gnome-libs. * doc/gdk-pixbuf.sgml: Added the animation section. * doc/Makefile.am (tmpl_sources): Added tmpl/animation.sgml. --- docs/reference/gdk-pixbuf/Makefile.am | 1 + docs/reference/gdk-pixbuf/gdk-pixbuf-decl.txt | 78 +++++---- .../gdk-pixbuf/gdk-pixbuf-sections.txt | 33 ++-- docs/reference/gdk-pixbuf/gdk-pixbuf.sgml | 6 +- docs/reference/gdk-pixbuf/tmpl/animation.sgml | 86 ++++++++++ .../gdk-pixbuf/tmpl/from-drawables.sgml | 5 +- .../gdk-pixbuf/tmpl/gdk-pixbuf-loader.sgml | 9 + docs/reference/gdk-pixbuf/tmpl/rendering.sgml | 3 +- docs/reference/gdk-pixbuf/tmpl/util.sgml | 1 - gdk-pixbuf/ChangeLog | 47 ++++- gdk-pixbuf/Makefile.am | 9 +- gdk-pixbuf/gdk-pixbuf-animation.c | 159 +++++++++++++++++ gdk-pixbuf/gdk-pixbuf-io.c | 160 +++++------------- gdk-pixbuf/gdk-pixbuf-io.h | 21 ++- gdk-pixbuf/gdk-pixbuf-loader.c | 6 +- gdk-pixbuf/gdk-pixbuf-loader.h | 2 +- gdk-pixbuf/gdk-pixbuf.c | 45 +---- gdk-pixbuf/gdk-pixbuf.h | 75 ++++---- gdk-pixbuf/io-gif.c | 9 +- gdk/gdkpixbuf-drawable.c | 8 +- gtk/gdk-pixbuf-loader.c | 6 +- gtk/gdk-pixbuf-loader.h | 2 +- 22 files changed, 499 insertions(+), 272 deletions(-) create mode 100644 docs/reference/gdk-pixbuf/tmpl/animation.sgml create mode 100644 gdk-pixbuf/gdk-pixbuf-animation.c diff --git a/docs/reference/gdk-pixbuf/Makefile.am b/docs/reference/gdk-pixbuf/Makefile.am index 6879618c9d..40d2a83956 100644 --- a/docs/reference/gdk-pixbuf/Makefile.am +++ b/docs/reference/gdk-pixbuf/Makefile.am @@ -17,6 +17,7 @@ HTML_DIR=$(datadir)/gnome/html TARGET_DIR=$(HTML_DIR)/$(DOC_MODULE) tmpl_sources = \ + tmpl/animation.sgml tmpl/creating.sgml \ tmpl/file-loading.sgml \ tmpl/from-drawables.sgml \ diff --git a/docs/reference/gdk-pixbuf/gdk-pixbuf-decl.txt b/docs/reference/gdk-pixbuf/gdk-pixbuf-decl.txt index a5246c9a8a..be6b6adab4 100644 --- a/docs/reference/gdk-pixbuf/gdk-pixbuf-decl.txt +++ b/docs/reference/gdk-pixbuf/gdk-pixbuf-decl.txt @@ -6,7 +6,9 @@ GdkPixbuf *pixbuf, gpointer user_data ModuleUpdatedNotifyFunc void -GdkPixbuf *pixbuf, gpointer user_data, guint x, guint y, guint width, guint height +GdkPixbuf *pixbuf, gpointer user_data, + guint x, guint y, + guint width, guint height GdkPixbufModule @@ -18,12 +20,15 @@ struct GdkPixbufModule { gboolean (* format_check) (guchar *buffer, int size); GModule *module; GdkPixbuf *(* load) (FILE *f); - GdkPixbuf *(* load_xpm_data) (const gchar **data); + GdkPixbuf *(* load_xpm_data) (const char **data); /* Incremental loading */ - gpointer (* begin_load) (ModulePreparedNotifyFunc prepare_func, ModuleUpdatedNotifyFunc update_func, gpointer user_data); - void (* stop_load) (gpointer context); - gboolean (* load_increment)(gpointer context, const gchar *buf, guint size); + + gpointer (* begin_load) (ModulePreparedNotifyFunc prepare_func, + ModuleUpdatedNotifyFunc update_func, + gpointer user_data); + void (* stop_load) (gpointer context); + gboolean (* load_increment) (gpointer context, const guchar *buf, guint size); /* Animation loading */ GdkPixbufAnimation *(* load_animation) (FILE *f); @@ -32,7 +37,7 @@ struct GdkPixbufModule { gdk_pixbuf_get_module GdkPixbufModule * -gchar *buffer,gint size +guchar *buffer, guint size gdk_pixbuf_load_module @@ -88,7 +93,7 @@ void gdk_pixbuf_loader_write gboolean -GdkPixbufLoader *loader,const gchar *buf,size_t count +GdkPixbufLoader *loader,const guchar *buf,size_t count gdk_pixbuf_loader_get_pixbuf @@ -114,19 +119,9 @@ GdkPixbufLoader *loader GdkPixbufAnimation - -GdkPixbufFrameAction -typedef enum -{ - GDK_PIXBUF_FRAME_RETAIN, - GDK_PIXBUF_FRAME_DISPOSE, - GDK_PIXBUF_FRAME_REVERT -} GdkPixbufFrameAction; - GdkPixbuf -struct GdkPixbuf -{ +struct GdkPixbuf { /* Reference count */ int ref_count; @@ -134,23 +129,41 @@ struct GdkPixbuf ArtPixBuf *art_pixbuf; }; + +GdkPixbufFrameAction +typedef enum { + GDK_PIXBUF_FRAME_RETAIN, + GDK_PIXBUF_FRAME_DISPOSE, + GDK_PIXBUF_FRAME_REVERT +} GdkPixbufFrameAction; + GdkPixbufFrame -struct GdkPixbufFrame -{ +struct GdkPixbufFrame { + /* The pixbuf with this frame's image data */ GdkPixbuf *pixbuf; - gushort x_offset; - gushort y_offset; - guint delaytime; + /* Offsets for overlaying onto the animation's area */ + int x_offset; + int y_offset; + + /* Frame duration in ms */ + int delay_time; + + /* Overlay mode */ GdkPixbufFrameAction action; }; GdkPixbufAnimation -struct GdkPixbufAnimation -{ +struct GdkPixbufAnimation { + /* Reference count */ + int ref_count; + + /* Number of frames */ int n_frames; + + /* List of GdkPixbufFrame structures */ GList *frames; }; @@ -217,7 +230,7 @@ ArtPixFormat format, gboolean has_alpha, int bits_per_sample,int width, int heig gdk_pixbuf_new_from_file GdkPixbuf * -const char *filename +const char *filename gdk_pixbuf_new_from_data @@ -227,7 +240,7 @@ guchar *data,ArtPixFormat format,gboolean has_alpha,int width, int height,int ro gdk_pixbuf_new_from_xpm_data GdkPixbuf * -const gchar **data +const char **data gdk_pixbuf_add_alpha @@ -264,12 +277,17 @@ GdkPixbuf *dest,GdkDrawable *src, GdkColormap *cmap,int src_x, int src_y,int des gdk_pixbuf_animation_new_from_file GdkPixbufAnimation * -const char *filename +const char *filename + + +gdk_pixbuf_animation_ref +void +GdkPixbufAnimation *animation -gdk_pixbuf_animation_destroy +gdk_pixbuf_animation_unref void -GdkPixbufAnimation *animation,gboolean free_frames +GdkPixbufAnimation *animation GNOME_TYPE_CANVAS_PIXBUF diff --git a/docs/reference/gdk-pixbuf/gdk-pixbuf-sections.txt b/docs/reference/gdk-pixbuf/gdk-pixbuf-sections.txt index 9bf5b214c0..bd2af95515 100644 --- a/docs/reference/gdk-pixbuf/gdk-pixbuf-sections.txt +++ b/docs/reference/gdk-pixbuf/gdk-pixbuf-sections.txt @@ -51,17 +51,13 @@ gdk_pixbuf_add_alpha
-gnome-canvas-pixbuf -GNOME_CANVAS_PIXBUF -GnomeCanvasPixbuf - -GNOME_TYPE_CANVAS_PIXBUF -GNOME_IS_CANVAS_PIXBUF -gnome_canvas_pixbuf_get_type -GNOME_CANVAS_PIXBUF_CLASS -GNOME_IS_CANVAS_PIXBUF_CLASS - -GnomeCanvasPixbuf +animation +GdkPixbufFrameAction +GdkPixbufFrame +GdkPixbufAnimation +gdk_pixbuf_animation_new_from_file +gdk_pixbuf_animation_ref +gdk_pixbuf_animation_unref
@@ -71,6 +67,7 @@ GDK_PIXBUF_LOADER gdk_pixbuf_loader_new gdk_pixbuf_loader_write gdk_pixbuf_loader_get_pixbuf +gdk_pixbuf_loader_get_animation gdk_pixbuf_loader_close GDK_TYPE_PIXBUF_LOADER @@ -81,3 +78,17 @@ GDK_IS_PIXBUF_LOADER_CLASS GdkPixbufLoader
+ +
+gnome-canvas-pixbuf +GNOME_CANVAS_PIXBUF +GnomeCanvasPixbuf + +GNOME_TYPE_CANVAS_PIXBUF +GNOME_IS_CANVAS_PIXBUF +gnome_canvas_pixbuf_get_type +GNOME_CANVAS_PIXBUF_CLASS +GNOME_IS_CANVAS_PIXBUF_CLASS + +GnomeCanvasPixbuf +
diff --git a/docs/reference/gdk-pixbuf/gdk-pixbuf.sgml b/docs/reference/gdk-pixbuf/gdk-pixbuf.sgml index b3e8b2cab1..b95e72f7fe 100644 --- a/docs/reference/gdk-pixbuf/gdk-pixbuf.sgml +++ b/docs/reference/gdk-pixbuf/gdk-pixbuf.sgml @@ -6,8 +6,9 @@ - + + ]> @@ -50,7 +51,8 @@ &gdk-pixbuf-rendering; &gdk-pixbuf-from-drawables; &gdk-pixbuf-util; - &GnomeCanvasPixbuf; + &gdk-pixbuf-animation; &GdkPixbufLoader; + &GnomeCanvasPixbuf; diff --git a/docs/reference/gdk-pixbuf/tmpl/animation.sgml b/docs/reference/gdk-pixbuf/tmpl/animation.sgml new file mode 100644 index 0000000000..8a5d558b60 --- /dev/null +++ b/docs/reference/gdk-pixbuf/tmpl/animation.sgml @@ -0,0 +1,86 @@ + +Animations + + +Animations as multi-frame structures. + + + + The GdkPixbuf library provides a simple mechanism to load and + represent animations, primarily animated GIF files. Animations + are represented as lists of #GdkPixbufFrame structures. Each + frame structure contains a #GdkPixbuf structure and information + about the frame's overlay mode and duration. + + + + + + #GdkPixbufLoader + + + + + + + + +@GDK_PIXBUF_FRAME_RETAIN: +@GDK_PIXBUF_FRAME_DISPOSE: +@GDK_PIXBUF_FRAME_REVERT: + + + + This structure describes a frame in a #GdkPixbufAnimation. Each + frame consists of a #GdkPixbuf, an offset of the frame within the + animation's bounding box, a duration, and an overlay mode or + action. + + +@pixbuf: The frame's image contents. +@x_offset: X offset of the frame inside the animation's bounding box. +@y_offset: Y offset of the frame inside the animation's bounding box. +@delay_time: Duration of the frame in milliseconds. +@action: Overlay mode. + + + + This structure describes an animation, which is represented as a + list of #GdkPixbufFrame structures. + + +@ref_count: Reference count. +@n_frames: Number of frames in the animation. +@frames: List of #GdkPixbufFrame structures. + + + + + + +@filename: +@Returns: + + + + + + + +@animation: + + + + + + + +@animation: + + + diff --git a/docs/reference/gdk-pixbuf/tmpl/from-drawables.sgml b/docs/reference/gdk-pixbuf/tmpl/from-drawables.sgml index e8efb59d97..3415bcb123 100644 --- a/docs/reference/gdk-pixbuf/tmpl/from-drawables.sgml +++ b/docs/reference/gdk-pixbuf/tmpl/from-drawables.sgml @@ -13,13 +13,11 @@ Getting parts of a drawable's image data into a pixbuf. transferred from the X server to the client program and converted. - #GdkPixbuf, gdk_image_get() - @@ -36,10 +34,11 @@ Getting parts of a drawable's image data into a pixbuf. @height: @Returns: - + + diff --git a/docs/reference/gdk-pixbuf/tmpl/gdk-pixbuf-loader.sgml b/docs/reference/gdk-pixbuf/tmpl/gdk-pixbuf-loader.sgml index e9052c94be..5638a1f345 100644 --- a/docs/reference/gdk-pixbuf/tmpl/gdk-pixbuf-loader.sgml +++ b/docs/reference/gdk-pixbuf/tmpl/gdk-pixbuf-loader.sgml @@ -54,6 +54,15 @@ Application-driven image loading. @Returns: + + + + + +@loader: +@Returns: + + diff --git a/docs/reference/gdk-pixbuf/tmpl/rendering.sgml b/docs/reference/gdk-pixbuf/tmpl/rendering.sgml index 68e5f616eb..a3f86c3701 100644 --- a/docs/reference/gdk-pixbuf/tmpl/rendering.sgml +++ b/docs/reference/gdk-pixbuf/tmpl/rendering.sgml @@ -104,8 +104,7 @@ In the future it will do full alpha compositing. @dest_y: @width: @height: -@alpha_threshold: -